package com.didispace.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.didispace.entity.AfterSale;
import com.didispace.exception.MyException;
import com.didispace.service.AfterSaleService;

/**
 *
 * @author 无鳍之鲨
 *
 */
@RestController
@CacheConfig(cacheNames = "users")
public class HelloController {
	
	@Autowired
	AfterSaleService afterSaleService;
	
    @RequestMapping(value = "/hello")
    public String index() throws Exception {
    	throw new Exception("故意报错");
    }
    
    @GetMapping("/json")
    public String json() throws MyException{
    	throw new MyException("测试JSON格式返回错误信息");
    }
    
    @GetMapping("/aftersale")
    @Cacheable(key = "'a'")
    public AfterSale selectCategory() {
    	System.out.println("111111111111111111111111111111111");
    	return afterSaleService.selectCategory();
    }
    
    @GetMapping("/delete")
    @CacheEvict(key = "'a'")
    public String delete() {
    	System.out.println("2222222222222222222222222222222222222");
    	return "缓存删除成功";
    }
}